You will undoubtedly find these topics useful when
you implement your own forms-based authentication
schemes.
Storing role information in a database is much more
convenient if you plan to create several different kinds
of roles or if they may change in the future.
Knowing that the FormsAuthentication object has a
SignOut method saves
you time because you don't have to write the code
yourself to destroy the FormsAuthenticationTicket and
cookie.
Detecting that a user is already logged in is quite
handy. When the user visits the login page after already
having logged in, you can display other useful
information or simply redirect the user away from the
login page. If you are implementing an authentication
scheme with multiple roles, you can ascertain what role
the logged-in user has and take appropriate action.
For example, the Page_Load function in
managerLogin.aspx (see Listing 5) redirects the logged-in user
to a different page based on the role
of the user. If the user has the manager
role, the index page in the manager folder
appears; if the user has the member role,
the website's home page appears. I wrote
the login procedure in managerLogin.aspx
this way because I figured if the user
is logged in as a member, he or she has
no business trying to log in as the managerso
why display the manager's login page?
Of course, this means that if the manager
happens to be logged in as a member, he
or she first has to log out and then log
in on the manager's login page. But this
seemed like a good security measure anyway. |